package com.hongmeng.web.controller.operater.newsAndVideo;

import java.util.List;

import com.hongmeng.operater.domain.newsAndVideo.entity.NewsInfoEntity;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hongmeng.common.annotation.Log;
import com.hongmeng.common.core.controller.BaseController;
import com.hongmeng.common.core.domain.AjaxResult;
import com.hongmeng.common.enums.BusinessType;
import com.hongmeng.operater.domain.newsAndVideo.HmNews;
import com.hongmeng.operater.service.newsAndVideo.IHmNewsService;
import com.hongmeng.common.utils.poi.ExcelUtil;
import com.hongmeng.common.core.page.TableDataInfo;

/**
 * 文章信息Controller
 *
 * @author hongmeng
 * @date 2020-12-21
 */
@Api("文章信息管理")
@RestController
@RequestMapping("/operater/news")
public class HmNewsController extends BaseController {
    @Autowired
    private IHmNewsService hmNewsService;

    /**
     * 查询文章信息列表
     */
    @ApiOperation("查询文章信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "标题", dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "keyWord", value = "关键字", dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "belongToSpecialty", value = "所属专科", dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "newsState", value = "状态", dataType = "String", paramType = "path")
    })
    @PreAuthorize("@ss.hasPermi('operater:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(String title,String keyWord,String belongToSpecialty,String newsState) {
        HmNews hmNews = new HmNews();
        hmNews.setTitle(title);
        hmNews.setKeyWord(keyWord);
        hmNews.setBelongToSpecialty(belongToSpecialty);
        hmNews.setNewsState(newsState);
        startPage();
        List<NewsInfoEntity> list = hmNewsService.selectHmNewsList(hmNews);
        return getDataTable(list);
    }

    /**
     * 导出文章信息列表
     */
    @PreAuthorize("@ss.hasPermi('operater:news:export')")
    @Log(title = "文章信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HmNews hmNews) {
        List<NewsInfoEntity> list = hmNewsService.selectHmNewsList(hmNews);
        ExcelUtil<NewsInfoEntity> util = new ExcelUtil<NewsInfoEntity>(NewsInfoEntity.class);
        return util.exportExcel(list, "news");
    }

    /**
     * 获取文章信息详细信息
     */
    @ApiOperation("获取文章信息详细信息")
    @ApiImplicitParam(name = "id", value = "文章ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('operater:news:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(hmNewsService.selectHmNewsById(id));
    }

    /**
     * 新增文章信息
     */
    @ApiOperation("新增文章信息")
    @PreAuthorize("@ss.hasPermi('operater:news:add')")
    @Log(title = "文章信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HmNews hmNews) {
        return hmNewsService.insertHmNews(hmNews);
    }

    /**
     * 修改文章信息
     */
    @ApiOperation("修改文章信息")
    @PreAuthorize("@ss.hasPermi('operater:news:edit')")
    @Log(title = "文章信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HmNews hmNews) {
        return toAjax(hmNewsService.updateHmNews(hmNews));
    }

    /**
     * 删除文章信息
     */
    @ApiOperation("删除文章信息")
    @PreAuthorize("@ss.hasPermi('operater:news:remove')")
    @Log(title = "文章信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(hmNewsService.deleteHmNewsByIds(ids));
    }

    /**
     * 审核文章信息
     */
    @ApiOperation("审核文章信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "文章id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "yesOrNo", value = "审核是否通过(true/false)", required = true, dataType = "boolean"),
            @ApiImplicitParam(name = "newsRemarks", value = "审核备注(通过与不通过的理由)", dataType = "String")
    })
    @PreAuthorize("@ss.hasPermi('operater:news:examine')")
    @PutMapping("/examine")
    public AjaxResult examine(Integer id, boolean yesOrNo, String newsRemarks) {
        return hmNewsService.examine(id, yesOrNo, newsRemarks);
    }

    /**
     * 获取文章信息详细信息(新增一个阅读量/浏览量)
     */
    @ApiOperation("获取文章信息详细信息新增一个阅读量/浏览量)")
    @ApiImplicitParam(name = "id", value = "文章ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('operater:news:queryAddCount')")
    @GetMapping(value = "/getNewsInfo/{id}")
    public AjaxResult getNewsInfo(@PathVariable("id") Integer id) {
        return hmNewsService.getNewsInfo(id);
    }
}
